package com.yunpeng.aidevice.common.enums;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * DeviceStateEnum
 *
 * @author : Moore(hemw)
 * @date : 2020-04-27
 */
public enum DeviceStateEnum {

    /**
     * 禁用状态
     */
    disabled("disabled", "已禁用"),
    /**
     * 正常状态
     */
    normal("normal", "正常状态");


    private String value;

    private String label;

    DeviceStateEnum(String value, String label) {
        this.value = value;
        this.label = label;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    private static Map<String, DeviceStateEnum> INTERNAL_MAP = new HashMap<>(16);

    /**
     * 获取用户状态枚举
     */
    public static DeviceStateEnum getEnumByValue(String value) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        if (INTERNAL_MAP.isEmpty()) {
            initMap();
        }
        return INTERNAL_MAP.get(value);
    }

    /**
     * 获取用户状态枚举描述
     */
    public static String getEnumLabelByValue(String value) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        if (INTERNAL_MAP.isEmpty()) {
            initMap();
        }
        DeviceStateEnum deviceStateEnum = INTERNAL_MAP.get(value);
        if (deviceStateEnum != null) {
            return deviceStateEnum.getValue();
        }
        return null;
    }

    private static void initMap() {
        for (DeviceStateEnum value : DeviceStateEnum.values()) {
            INTERNAL_MAP.put(value.value, value);
        }
    }

}
